package com.audaque.springboot.foshanupload.web.raspcloud.controller.ext;

import com.audaque.springboot.foshanupload.authcore.model.currentUser.TransmittableThreadLocalCurrentUser;
import com.audaque.springboot.foshanupload.web.raspcloud.mapper.ext.MenuExtMapper;
import com.audaque.springboot.foshanupload.web.raspcloud.rsp.MenuRsp;
import com.audaque.springboot.foshanupload.web.raspcloud.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;


/**
 * <p>
 * 后台菜单表 前端控制器
 * </p>
 *
 * @author chinaben
 * @since 2025-07-02
 */
@RestController

@Api(value = "后台菜单表 前端控制器")

@RequestMapping("/menuExt")
public class MenuExtController {

    @Autowired
    private MenuExtMapper menuExtMapper;
    @Autowired
    private IMenuService iMenuService;
    @GetMapping(value = "/current")
    @ApiOperation(value = "后台菜单表 列表查询")
    public List<MenuRsp> current() {
        TransmittableThreadLocalCurrentUser currentUser = TransmittableThreadLocalCurrentUser.getCurrentUser();

        List<Long> roleIds = currentUser.getRoleIds().stream().map(e->{
            if(e.contains("ROLE_")){
               e = e.replace("ROLE_", "");
            }
            return Long.parseLong(e);
        }).collect(Collectors.toList());

        List<MenuRsp> list = menuExtMapper.getMenusByRoleIds(roleIds);
        return list;
    }






}
